var express = require('express');
var router = express.Router();

//引入连接数据库模块
const connection = require('./conn')

//连接数据
connection.connect( () => {
  console.log('数据库连接成功')
})

//接收登录请求
router.post('/checklogin',(req, res) => {
  //接收用户名和密码
  let {username, password} = req.body;
  console.log('-----------'+username,password);

  //去数据库查询是否存在这个账号和密码的用户
  //执行SQL查询
  const sqlStr = `select * from users where username="${username}" and password="${password}"`;
  connection.query(sqlStr, (err,data) => {
    if(err){
      //
      throw err;
    }else{
      res.send(data)
      console.log(data)
    }
  })
})

module.exports = router;


